/**
 * Copyright (c) Huawei Technologies Co., Ltd. 1987-2021. All rights reserved.
*/

package com.gitee.fufu669.utils;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * @author wangfupeng
 */
public class CacheTableUtil {

    /**
     * TODO
    */
    public static final Logger logger = LoggerFactory.getLogger(CacheStringUtils.class);

    /**
     * TODO
    */
    public static String toTransferTableNameToObjectName(String tableName) {
        // 切分
        String[] tableNames = tableName.split("_");
        // 赋值
        String objectName = "";
        // 遍历
        for (int i = 0; i < tableNames.length; i++) {
            // 增加
            objectName += toUpperCaseAtFirstCharacter(tableNames[i]);
        }
        // 返回
        return objectName;
    }

    /**
     * TODO
    */
    public static String toUpperCaseAtFirstCharacter(String tableName) {
        // 创建
        StringBuilder sb = new StringBuilder(tableName);
        // TODO
        sb.setCharAt(0, Character.toUpperCase(sb.charAt(0)));
        // 返回
        return sb.toString();
    }

    /**
     * TODO
    */
    public static String toLowerCaseAtFirstCharacter(String tableName) {
        // 创建
        StringBuilder sb = new StringBuilder(tableName);
        // TODO
        sb.setCharAt(0, Character.toLowerCase(sb.charAt(0)));
        // 返回
        return sb.toString();
    }

    /**
     * TODO
    */
    public static String getProperCase(String s) {
        // 返回
        return s.substring(0, 1).toUpperCase() + s.substring(1);
    }

    /**
     * TODO
    */
    public static String getLowerCaseAndSpliter(String s, String spliter) {
        // 判断是否是空
        if (s == null) {
            // 返回
            return "";
        }
        // 判断
        if (s.equals("")) {
            // 返回
            return "";
        }
        // 字符串赋值
        String result = ("" + s.charAt(0)).toLowerCase();
        // 遍历
        for (int i = 1; i < s.length(); i++) {
            // 赋值
            String c = "" + s.charAt(i);
            // 判断
            if (c.toUpperCase().equals(c)) {
                // 增加
                result += spliter + c.toLowerCase();
            // 否则
            } else {
                // 增加
                result += c;
            }
        }
        // 返回
        return result;
    }

}
